package org.hit.burkun.mapping;

import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.hit.burkun.db.DBHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class BlockOfflineMapping extends BasicOfflineMapping {

	private Map<String, Set<String>> resMap;
	private static Logger logger = LoggerFactory
			.getLogger(BasicOfflineMapping.class);

	public BlockOfflineMapping(DBHelper dbHelper) {
		super(dbHelper);
		resMap = new HashMap<String, Set<String>>();
	}

	@Override
	public void mapping(DBKEY fromKey, DBKEY toKey, Collection<String> data) {
		resMap.clear();
		super.mapping(fromKey, toKey, data);
	};

	@Override
	public void process(DBKEY fromKey, DBKEY toKey,
			Map<String, Set<String>> resData) {
		super.process(fromKey, toKey, resData);
		logger.debug("add return res to mapping dictory!");
		resMap.putAll(resData);
	}
	
	
	public static void main(String[] args){
		BlockOfflineMapping bm = new BlockOfflineMapping(DBHelper.getServerData());
		LinkedList<String> data = new LinkedList<>();
		data.add("P18031");
		bm.begin();
		bm.mapping(DBKEY.UniProtKB_AC, DBKEY.GENE_SYMBOL, data);
		bm.end();
		Map<String, Set<String>> res = bm.getResult();
		Set<String> keys = res.keySet();
		for(String key : keys){
			System.out.println(StringUtils.join(res.get(key), ","));
		}
	}

	public Map<String, Set<String>> getResult() {
		return resMap;
	}
}
